# 交叉编译器
CXX = aarch64-linux-gnu-g++
CC  = aarch64-linux-gnu-gcc

# 源文件
SOURCES = main.cpp function.cpp commom.cpp
OBJECTS = $(SOURCES:.cpp=.o)
TARGET  = show_image

BUILD_DIR = build

# libjpeg 路径（你已经编译好的）
LIBJPEG_PATH = ./jpeg-arm64
LIBJPEG_LIB  = $(LIBJPEG_PATH)/lib
LIBJPEG_INCLUDE = $(LIBJPEG_PATH)/include

# 编译选项
CXXFLAGS = -Wall -Wextra -O2 -I$(LIBJPEG_INCLUDE) -I.
LDFLAGS  = -L$(LIBJPEG_LIB) -ljpeg -pthread

# 默认目标
all: $(TARGET)

# 链接
$(TARGET): $(OBJECTS)
	@mkdir -p $(BUILD_DIR)
	$(CXX) $(addprefix $(BUILD_DIR)/, $(OBJECTS)) -o $(BUILD_DIR)/$(TARGET) $(LDFLAGS)

# 编译规则
%.o: %.cpp
	@mkdir -p $(BUILD_DIR)
	$(CXX) $(CXXFLAGS) -c $< -o $(BUILD_DIR)/$@

# 清理
clean:
	rm -f build/*.o build/$(TARGET)

# 重新编译
re: clean all

# 推送到开发板（可选）
push:
	scp build/$(TARGET) root@192.168.3.149:/root/

# 运行（可选）
run: push
	ssh root@192.168.3.149 "/root/$(TARGET)"

.PHONY: all clean re push run